home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v7n19.arc / SUMDIR.PAS < prev    next >
Pascal/Delphi Source File  |  1988-10-14  |  1KB  |  38 lines

  1. {$P512,G512,D-,R+}
  2. { USAGE: e.g., "DIR | SUMDIR" or "DIR *.PAS | SUMDIR" }
  3. PROGRAM SumDir;
  4. VAR
  5.   Line       : STRING[255]; {input line from directory    }
  6.   Code       : Integer;     {error code for VAL procedure }
  7.   FileLenStr : STRING[7];   {file-length part of Line     }
  8.   FileLen,                  {file length as a number      }
  9.   Sum        : Real;        {total of file lengths        }
  10.  
  11. BEGIN
  12.   Sum := 0;
  13.   WHILE NOT EoF DO
  14.     BEGIN
  15.       ReadLn(line);                       {Read a directory line}
  16.       IF (Line[0] >= #22) AND (Line[1] <> ' ') THEN
  17.         BEGIN
  18.           FileLenStr := Copy(line, 15, 7);{Extract file length  }
  19.           WHILE FileLenStr[1] = ' ' DO    {Strip leading blanks }
  20.             Delete(FileLenStr, 1, 1);
  21.           Val(FileLenStr, FileLen, Code); {Make it a number     }
  22.           IF code = 0 THEN
  23.             Sum := Sum+FileLen;           {Add it to the sum    }
  24.           WriteLn(Line);
  25.         END
  26.       ELSE
  27.         BEGIN
  28.           IF Copy(line, 11, 7) = 'File(s)' THEN
  29.             {this is the LAST line of the directory -- fix it}
  30.             BEGIN
  31.               WHILE Line[1] = ' ' DO      {Strip leading blanks }
  32.                 Delete(Line, 1, 1);
  33.               Write(sum:10:0,' bytes in ');
  34.             END;
  35.           WriteLn(Line);
  36.         END;
  37.     END;
  38. END.